# -*- coding: utf-8 -*-
# @Time : 2020/9/24 16:27
# @Author : HEAD
# @Email : scg@gmail.com
# @File : data.py
# @Project : scg_interface
"""
从Excel中读取接口数据
"""
import xlrd
import os
from lib.config import Config,base_path

c = Config()


class Data:
    """Data类，用于从excel文件中读取测数据"""

    def __init__(self, filename):
        data_file_path = os.path.join(base_path, c.get_runtime('data_dir'), filename)
        self.wb = xlrd.open_workbook(data_file_path)

    def get_case(self, sheet_name, case_name):
        """根据excel sheet名称和testCase名称获取数据"""
        sheet = self.wb.sheet_by_name(sheet_name)
        for i in range(1, sheet.nrows):
            if sheet.cell(i, 0).value == case_name:
                return sheet.row_values(i)


if __name__ == '__main__':
    data = Data('test_user_ata.xlsx')
    print(data.get_case('login','test_login_normal_n'))